/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.execute.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.approval.vo.WaitPageEachColorNumVo;
import com.icinfo.cloud.provider.punish.execute.dto.*;
import com.icinfo.cloud.provider.punish.execute.service.IExecuteCompleteRecordService;
import com.icinfo.cloud.provider.punish.execute.service.IExecuteMainInfoService;
import com.icinfo.cloud.provider.punish.execute.service.impl.ExecuteMainInfoServiceImpl;
import com.icinfo.cloud.provider.punish.execute.vo.*;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 描述: 裁执分离主表 execute_main_info 对应的Controller类.<br>
 *
 * @author framework generator
 * @date 2022年08月24日
 */
@RestController
@RequestMapping("/execute")
public class ExecuteMainInfoController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(ExecuteMainInfoController.class);

    @Autowired
    private IExecuteMainInfoService executeMainInfoService;
    @Autowired
    private IExecuteCompleteRecordService executeCompleteRecordService;
    @Resource
    private ExecuteMainInfoServiceImpl service;

    /**
     * 描述: 裁执分离保存，提供给法院调用，推送裁执分离数据
     *
     * @param saveDto
     * @return com.icinfo.framework.common.web.Result<java.lang.String>
     * @author zhanghongqiang
     * @Date 2022/8/24
     */
    @PostMapping("/addExecuteMainInfo")
    @ApiOperation(value = "裁执分离保存，提供给法院调用，推送裁执分离数据", httpMethod = "POST")
    public Result<String> addExecuteMainInfo(@RequestBody @Validated ExecuteMainInfoInsertDto saveDto) {
        return executeMainInfoService.saveExecuteMainInfo(saveDto);
    }

    /**
     * 描述: 裁执分离列表,分页查询
     *
     * @param request
     * @return com.icinfo.framework.common.web.Result
     * @author zhanghongqiang
     * @Date 2022/8/25
     */
    @PostMapping("/readExecuteMainList")
    @ApiOperation(value = "裁执分离列表,分页查询", httpMethod = "POST")
    public Result<PageResponse<ExecuteMainInfoVo>> readExecuteMainList(@RequestBody @Validated ExecuteMainInfoRequest request) {
        List<ExecuteMainInfoVo> executeMainPageNewVos = executeMainInfoService.getExecuteMainList(request);
        return Result.success(Constant.STRING_GET_SUCCESS, new PageResponse<>(executeMainPageNewVos));
    }

    /**
     * 描述: 裁执分离列表,时效条件查询（红黄蓝）
     *
     * @param request
     * @return com.icinfo.framework.common.web.Result
     * @author zhanghongqiang
     * @Date 2022/8/31
     */
    @PostMapping("/readExecutePrescription")
    @ApiOperation(value = "裁执分离列表,时效条件查询", httpMethod = "POST")
    public Result<WaitPageEachColorNumVo> readExecutePrescription(@RequestBody @Validated ExecuteMainInfoRequest request) {
        WaitPageEachColorNumVo executePrescription = executeMainInfoService.getExecutePrescription(request);
        return Result.success(Constant.STRING_GET_SUCCESS, executePrescription);
    }

    /**
     * 描述: 裁执分离列表,状态数量
     *
     * @param request
     * @return com.icinfo.framework.common.web.Result
     * @author zhanghongqiang
     * @Date 2022/8/31
     */
    @PostMapping("/readExecuteStatesNum")
    @ApiOperation(value = "裁执分离列表,状态数量", httpMethod = "POST")
    public Result<ExecuteStatesNumVo> readExecuteStatesNum(@RequestBody @Validated ExecuteMainInfoRequest request) {
        ExecuteStatesNumVo executeStatesNumVo = executeMainInfoService.getExecuteStatesNum(request);
        return Result.success(Constant.STRING_GET_SUCCESS, executeStatesNumVo);
    }

    /**
     * 【V1.4.2】裁执分离详情
     *
     * @param executeDetailDto
     * @return {@link Result< String>}
     * @author wuzhihui
     * @date 2022/8/29
     */
    @PostMapping(value = "/getExecuteDetailMainInfo")
    public Result<ExecuteDetailVo> getExecuteDetailMainInfo(@RequestBody @Validated ExecuteDetailDto executeDetailDto) {
        ExecuteDetailVo vo = executeMainInfoService.getExecuteDetail(executeDetailDto);
        return Result.success(vo);
    }

    /**
     * 【V1.4.2】裁执分离详情基本信息
     *
     * @param executeDetailDto
     * @return {@link Result< String>}
     * @author wuzhihui
     * @date 2022/8/29
     */
    @PostMapping(value = "/getExecuteMainInfo")
    public Result<ExecuteDetailVo> getExecuteMainInfo(@RequestBody @Validated ExecuteDetailDto executeDetailDto) {
        ExecuteDetailVo vo = executeMainInfoService.getExecuteMainInfo(executeDetailDto);
        return Result.success(vo);
    }

    /**
     * 根据裁执分离阶段获取对应文书
     *
     * @param queryDto
     * @return {@link Result<  ExecuteStageDocumentInfoVo >}
     * @author wuzhihui
     * @date 2022/8/29
     */
    @PostMapping("/getExecuteDocumentInfo")
    public Result<List<ExecuteStageDocumentInfoVo>> getExecuteStageDocumentInfo(@RequestBody @Validated ExecuteStageDocumentQueryDto queryDto) {
        List<ExecuteStageDocumentInfoVo> vos = executeMainInfoService.getExecuteStageDocumentInfo(queryDto);
        return Result.success(Constant.STRING_GET_SUCCESS, vos);
    }

    /**
     * 描述: 审批详情页裁执分离基本信息
     *
     * @param executeDetailDto
     * @return com.icinfo.framework.common.web.Result
     * @author zhanghongqiang
     * @Date 2022/9/6
     */
    @PostMapping(value = "/readExecuteApprovalDetail")
    public Result<ExecuteApprovalVo> readExecuteApprovalDetail(@RequestBody @Validated ExecuteDetailDto executeDetailDto) {
        ExecuteApprovalVo vo = executeMainInfoService.getExecuteApprovalDetail(executeDetailDto);
        return Result.success(vo);
    }
    /**
     * 描述：保存强制执行完毕信息
     * @author wuzhihui
     * @date 2022/9/06
     * @param saveDto
     * @return {@link Result < String>}
     */
    /*@PostMapping("/saveCompleteInfo")
    @ApiOperation(value = "【V1.4.2】描述：保存强制执行完毕信息", httpMethod = "POST")
    public Result<String> saveCompleteInfo(@RequestBody @Validated ExecuteCompleteSaveDto saveDto) {
        boolean isSuccess = executeCompleteRecordService.saveCompleteInfo(saveDto);
        return isSuccess ? Result.success(Constant.STRING_SAVE_SUCCESS) :Result.success(Constant.STRING_SAVE_FAIL);
    }*/
    /**
     * 描述：获取强制执行完毕信息
     * @author wuzhihui
     * @date 2022/9/06
     * @param saveDto
     * @return {@link Result < String>}
     */
    @PostMapping("/getCompleteInfo")
    @ApiOperation(value = "【V1.4.2】描述：保存强制执行完毕信息", httpMethod = "POST")
    public Result<ExecuteCompleteVo> getCompleteInfo(@RequestBody @Validated ExecuteCompleteRequestDto saveDto) {
        ExecuteCompleteVo executeCompleteVo = executeCompleteRecordService.getCompleteInfo(saveDto);
        return  Result.success(executeCompleteVo);
    }
    /**
     * 描述：结案
     * @author wuzhihui
     * @date 2022/9/06
     * @param saveDto
     * @return {@link Result < String>}
     */
    @PostMapping("/closeExecute")
    @ApiOperation(value = "【V1.4.2】描述：保存结案信息", httpMethod = "POST")
    public Result<ExecuteCloseVoDto> closeExecute(@RequestBody @Validated ExecuteCloseSaveDto saveDto) {
        ExecuteCloseVoDto executeCloseVoDto = executeMainInfoService.closeExecute(saveDto);
        return  Result.success(executeCloseVoDto);
    }
    /**
     * 描述：结案
     * @author wuzhihui
     * @date 2022/9/06
     * @param requestDto
     * @return {@link Result < String>}
     */
    @PostMapping("/getCloseExecuteInfo")
    @ApiOperation(value = "【V1.4.2】描述：获取结案信息", httpMethod = "POST")
    public Result<ExecuteCloseInfoVo> getCloseExecuteInfo(@RequestBody @Validated ExecuteCloseRequestDto requestDto) {
        ExecuteCloseInfoVo executeCloseInfoVo = executeMainInfoService.getCloseExecuteInfo(requestDto);
        return Result.success(executeCloseInfoVo);
    }


    /**
     * 描述：裁执分离执行完毕
     *
     * @param executePunishActionDto {@link ExecutePunishActionDto}
     * @return Result 操作结果
     * @author wuzhihui
     * @date 2022-04-29 14:45
     */
    @PostMapping("/saveCompleteInfo")
    @ApiOperation(value = "【V1.4.2】描述：案件处罚执行完毕", httpMethod = "POST")
    public Result saveCompleteInfo(@Validated @RequestBody ExecutePunishActionDto executePunishActionDto) {
        if (executeMainInfoService.savePunishExecuteInfo(executePunishActionDto).size() > 0) {
            return Result.success("success");
        }
        return Result.error("fail");
    }
}